/*                         _oo0oo_
                          o8888888o
                          88" . "88
                          (| -_- |)
                          0\  =  /0
                        ___/‘---’\___
                      .' \\|     |// '.
                     / \\|||  :  |||// \
                    / _||||| -:- |||||_ \
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |_/ |
                   \  .-\__  '-'  __/-.  /
                 ___'. .'  /--.--\  '. .'___
              .""  '< '.___\_<|>_/___.' >'  "".
             | | :   '-\'.:'\ _ /':.'/- '  : | |
             \  \ '_.   \_ __\ /__ _/   ._' /  /
         ====='-.____'.    \_____/    .'____._'=====
                           '=---='
                           
                                                      
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     佛祖保佑                                                                                                       永无BUG
 */



/**

* Copyright ©, 2018-,clz. All rights reserved.
* FileName: Config.java
* @Description 此类用于对整个项目进行配置
*
* @author 陈凌志
* @Date 2018.2.5
* @version 1.00
*/

package config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.template.Engine;

import config.model._MappingKit;
import interceptor.LoginInterceptor;


public class Config extends JFinalConfig{
	
	/**
	* 此方法用于开发模式常量devMode进行配置
	* 在开发模式下，JFinal会对每次请求输出报告，如输出本次请求的URL、Controller、Method以及请求所携带的参数。
	*
	*/

	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		PropKit.use("a_little_config.txt");
		me.setBaseUploadPath("file");
		me.setDevMode(true);
	}

	public void configEngine(Engine me) {
		// TODO Auto-generated method stub
		//添加模板paginate
		me.addSharedFunction("/common/_layout.html");
		me.addSharedFunction("/common/_paginate.html");
		me.addSharedFunction("/common/_adminNav.html");
		me.addSharedFunction("/common/_studentNav.html");
		me.addSharedFunction("/common/_teacherNav.html");
		me.addSharedFunction("/common/_excel.html");
		
		
		
	}

	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		
	}

	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		//配置全局拦截器，用于拦截某些人未登录时直接定向到非登录页面
		me.add(new LoginInterceptor());
		me.add(new SessionInViewInterceptor());
	}

	public static DruidPlugin createDruidPlugin() {
		return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
	}
	
	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		//开启缓存配置
		me.add(new EhCachePlugin());
		
		// 配置数据库连接池插件
		DruidPlugin druidPlugin = createDruidPlugin();
		me.add(druidPlugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		// 所有映射在 MappingKit 中自动化搞定
		_MappingKit.mapping(arp);
		me.add(arp);
	}

	/**
	* 此方法用来配置访问路由
	*
	*/
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/",controller.IndexController.class,"/");
		me.add("/admin",controller.AdminController.class,"/admin");
		me.add("/student",controller.StudentController.class,"/student");
		me.add("/teacher",controller.TeacherController.class,"/teacher");
	}

}
